package id.co.rho.scoring.cid.client.mvc.typemodelconfig;

import id.co.rho.scoring.cid.client.mvc.AppView;

import com.extjs.gxt.ui.client.Registry;
import com.extjs.gxt.ui.client.widget.ContentPanel;
import com.extjs.gxt.ui.client.widget.LayoutContainer;
import com.extjs.gxt.ui.client.widget.button.Button;
import com.extjs.gxt.ui.client.widget.form.FieldSet;
import com.extjs.gxt.ui.client.widget.form.FormPanel;
import com.extjs.gxt.ui.client.widget.form.TextArea;
import com.extjs.gxt.ui.client.widget.form.TextField;
import com.extjs.gxt.ui.client.widget.layout.FormLayout;
import com.extjs.gxt.ui.client.widget.layout.HBoxLayout;
import com.extjs.gxt.ui.client.widget.layout.VBoxLayout;
import com.extjs.gxt.ui.client.widget.layout.VBoxLayoutData;
import com.extjs.gxt.ui.client.Style;

public class TypeModelConfigUIWeb implements TypeModelConfigUI{
	private ContentPanel dataPanel;
	private TextField<String> txtName;
	private TextField<String> txtCode;
	private TextArea txtDescr;
	private Button btnSave;
	private Button btnDelete;
	private Button btnCancel;
	private FormLayout formLayout;
    private FieldSet fsInput;
	private VBoxLayoutData vbData;
	private VBoxLayout vBoxLayout;
	private FormPanel formPanel;

	@Override
	public void initialize() {
		fsInput = new FieldSet();
		dataPanel = new ContentPanel();
		
		formLayout = new FormLayout();
        formLayout.setLabelAlign(FormPanel.LabelAlign.LEFT);
        
        fsInput = new FieldSet();
        fsInput.setHeading("Type Model Config");
        fsInput.setLayout(formLayout);
        
        vBoxLayout = new VBoxLayout(VBoxLayout.VBoxLayoutAlign.STRETCH);		
        vbData = new VBoxLayoutData();
		
		txtName = new TextField<String>();
		txtName.setFieldLabel("Name");
		txtCode = new TextField<String>();
		txtCode.setFieldLabel("Code");
		txtDescr = new TextArea();
		txtDescr.setFieldLabel("Description");
		
		fsInput.add(txtName);
		fsInput.add(txtCode);
		fsInput.add(txtDescr);	
		
        formPanel = new FormPanel();
        formPanel.setHeading("Type Model Config");
        formPanel.setScrollMode(Style.Scroll.AUTO);
        formPanel.add(fsInput);
		
        LayoutContainer lcButton = new LayoutContainer();        
        lcButton.setStyleAttribute("margin-top", "10px");
        lcButton.setLayout(new HBoxLayout());
        fsInput.add(lcButton);
		btnSave = new Button();
		btnSave.setStyleAttribute("padding-left", "5px");
		btnSave.setText("Save");
		btnDelete = new Button();
		btnDelete.setStyleAttribute("padding-left", "5px");
		btnDelete.setText("Delete");
		btnCancel = new Button();
		btnCancel.setStyleAttribute("padding-left", "5px");
		btnCancel.setText("Cancel");
		lcButton.add(btnSave);
//		lcButton.add(btnDelete);
		lcButton.add(btnCancel);
		dataPanel.add(formPanel,vbData);
	}

	@Override
	public void show() {
		ContentPanel centerPanel = (ContentPanel) Registry
				.get(AppView.CENTER_PANEL);
		centerPanel.removeAll();
		centerPanel.add(formPanel,vbData);
		centerPanel.layout();
	}
	
	public void clearText(){
		txtCode.setValue("");
		txtName.setValue("");
		txtDescr.setValue("");
		fsInput.layout();
	}

	public TextField<String> getTxtName() {
		return txtName;
	}

	public TextField<String> getTxtCode() {
		return txtCode;
	}

	public TextArea getTxtDescr() {
		return txtDescr;
	}

	public Button getBtnSave() {
		return btnSave;
	}

	public Button getBtnDelete() {
		return btnDelete;
	}

	public Button getBtnCancel() {
		return btnCancel;
	}

}
